<template>
    <div id="app" class="app-view">
        <router-view v-if="isRouterAlive"></router-view>
    </div>
</template>

<script>
import { ref, nextTick, provide } from 'vue';
import { useRouter } from 'vue-router';
import { objectToFormData, getCookie } from '@/utils/utils';
import { baseLogUrl } from '@/api/api.request';
const router = useRouter();
let currentTime;
// 点击页签关闭按钮前端埋点
window.onbeforeunload = () => {
    const currentRouteData = router.currentRoute.value;
    currentTime = Date.now();
    const token = getCookie('SaaS_Token') ? getCookie('SaaS_Token') : '';
    const actData = {
        model: 'saas-housekeeper-web-worker',
        page: currentRouteData.path.replace(/\//g, '_').slice(1),
        ts: currentTime,
        token: token,
    };
    const actions = [
        {
            item: 'close',
            descriptions: '用户点击页签关闭按钮',
        },
    ];
    const actData2 = objectToFormData(actData);
    actData2.append('actions', JSON.stringify(actions));
    navigator.sendBeacon(baseLogUrl + 'log/logger', actData2);
};
export default {
    name: 'App',
    components: {},
    setup() {
        const isRouterAlive = ref(true);
        const reload = () => {
            isRouterAlive.value = false;
            nextTick(() => {
                isRouterAlive.value = true;
            });
        };
        provide('reload', reload);
        return {
            isRouterAlive,
        };
    },
};
</script>

<style lang="scss"></style>
